<?php namespace web\home\controller;
/** .-------------------------------------------------------------------
 * |  Software: [HDPHP framework]
 * |      Site: www.hdphp.com
 * |-------------------------------------------------------------------
 * |    Author: 向军 <2300071698@qq.com>
 * |    WeChat: aihoudun
 * | Copyright (c) 2012-2019, www.houdunwang.com. All Rights Reserved.
 * '-------------------------------------------------------------------*/

class Conf_common {
	
	//构造函数	
	public function __construct(){
		if($_SESSION['id']){
			View::with('session',$_SESSION);
//			p($_SESSION);
		}
		
		
//		一级导航数据
		$dhData=Db::table('category')->where('pid',0)->get();
		View::with('dhData',$dhData);
//		p($dhData);dei;
		
//		获取所有分类数据
		$daohang=Db::table('category')->get();
//		所在位置
		$cid=Q('get.cid',0,'intval');
		$pid=Db::table('category')->where('cid',$cid)->pluck('pid');
//		p($daohang);die;
		$dhlist=$this->getDh($pid,$daohang);
		$dhlist[]=$pid;
		sort($dhlist);
		foreach($dhlist as $k=>$v){
			if($v!=0){
			$dhlist2[$k]=Db::table('category')->where('cid',$v)->pluck('cname');
			}
		}
//		p($dhlist);die;
		View::with('dhlist',$dhlist2);
//		获取分类导航
		foreach($dhData as $k=>$v){
			$dhData[$k]['two']=Db::table('category')->where('pid',$v['cid'])->get();
			foreach($dhData[$k]['two'] as $kk=>$vv){
				$dhData[$k]['two'][$kk]['thr']=Db::table('category')->where('pid',$vv['cid'])->get();
			}
		}
		
		View::with('navData',$dhData);
//		购物车数据
		if(isset($_SESSION['cart']['goods']) && !empty($_SESSION['cart']['goods'])){
			$shopnum=\Cart::getTotalNums();
		}else{
			$shopnum=0;
		}
		View::with('shopnum',$shopnum);
		
		
	
		
	}

	public function getDh($pid,$data){
		$temp=array();
		foreach($data as $k=>$v){
				if($pid==$v['cid']){
				$temp[]=$v['pid'];
				$temp=array_merge($temp,$this->getDh($v['pid'],$data));
				}
		}
		return $temp;
	}
	
}